package cn.johnyu.controller;

import jakarta.annotation.Resource;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {
    @Resource
    private RestClient.Builder restClientBuilder;
    @Resource
    private RestTemplate restTemplate;
    @GetMapping("/order/{id}")
    public ResponseEntity<String> loadOrderById(@PathVariable("id") int id){

//        RestClient client=RestClient.builder().baseUrl("http://order-service").build();
        String products = restClientBuilder.build().method(HttpMethod.GET).uri("products").retrieve().body(String.class);
        return ResponseEntity.ok(products);
//       String info= restClient.get()
//               .uri("products")
//               .header("Content-Type","application/json")
//               .accept(MediaType.APPLICATION_JSON)
//               .exchange((req,resp)->resp.bodyTo(String.class));
//       return ResponseEntity.ok("Ok......");
//        String info=  restTemplate.getForObject("http://product-service/products",String.class);
//        return ResponseEntity.ok(info);

    }
}
